<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: content_manager.php 225 2013-09-22 10:21:51Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 225 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 10:21:51 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if($_GET['action'] != 'new') {
	$content = $db->db_query("SELECT
								*
							FROM
								".TABLE_CONTENT_MANAGER."
							WHERE
								content_id='".(int)$_GET['coID']."'");
  $content_group = $content->fields['content_group'];
}
else {
	$contentMax = $db->db_query("SELECT
                max(content_group) content_group
							FROM
								".TABLE_CONTENT_MANAGER);
  $content_group = $contentMax->fields['content_group']+1;
}

$languages = get_languages();

if($_GET['action']!='new')
	echo draw_form('edit_content', FILENAME_CONTENT_MANAGER, 'action=edit&id=update&coID='.$_GET['coID'], 'post', 'enctype="multipart/form-data"').
	draw_hidden_field('coID',$_GET['coID']);
else
	echo draw_form('edit_content', FILENAME_CONTENT_MANAGER, 'action=edit&id=insert', 'post', 'enctype="multipart/form-data"').
	draw_hidden_field('coID',$_GET['coID']);
?>
	<table width="100%">
		<tr>
			<td colspan="2" align="right">
				<button type="submit" class="button"><?php echo BUTTON_SAVE ?></button>
				<button type="submit" class="button" name="apply_content">&Uuml;bernehmen</button> 
				<a class="button" onclick="this.blur();" href="<?php echo href_link(FILENAME_CONTENT_MANAGER); ?>">
					<?php echo BUTTON_BACK; ?>
				</a>
			</td>
		</tr>
	</table><br />
	<div id="content_manager">
		<ul>
			<li><a href="#desc" onclick="return false">Texte</a></li>
			<li><a href="#misc" onclick="return false">Einstellungen</a></li>
		</ul>
		<div id="desc">
			<div id="tabs">
				<ul>
					<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
						<li><a href="#language_<?php echo $languages[$i]['id']; ?>">
							<span><img src="../lang/<?php echo $languages[$i]['directory'].'/'.$languages[$i]['image']; ?>" alt="" /> <?php echo $languages[$i]['name'] ?></span>
						</a></li>
					<?php } ?>
				</ul>
				<?php 
					for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { 
					$lid = $languages[$i]['id'];
				?>
				<div id="language_<?php echo $lid ?>">
					<?php
						$title = '';
						$heading = '';
						$url_alias = '';
						$meta_title = '';
						$meta_desc = '';
						$meta_keyw = '';
						$text = '';
						
						if($_GET['action'] != 'new') {
							$desc = $db->db_query("SELECT
														content_title,
														content_heading,
														content_text,
														content_meta_title,
														content_meta_description,
														content_meta_keywords,
														content_url_alias
													FROM
														".TABLE_CONTENT_MANAGER."
													WHERE
														content_id = '".(int)$_GET['coID']."'
													AND
														languages_id = '".(int)$lid."'");

							$title = $desc->fields['content_title'];
							$heading = $desc->fields['content_heading'];
							$url_alias = $desc->fields['content_url_alias'];
							$meta_title = $desc->fields['content_meta_title'];
							$meta_desc = $desc->fields['content_meta_description'];
							$meta_keyw = $desc->fields['content_meta_keywords'];
							$text = $desc->fields['content_text'];	
						}
					?>
					<table width="100%" cellpadding="4">
						<tr>
							<td style="background:#e2e2e2"><?php echo TEXT_TITLE; ?></td>
							<td style="background:#e2e2e2"><?php echo draw_input_field('cont_title_'.$lid, $title, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td><?php echo TEXT_HEADING; ?></td>
							<td><?php echo draw_input_field('cont_heading_'.$lid, $heading, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td>URL Alias:</td>
							<td><?php echo draw_input_field('cont_url_alias_'.$lid, $url_alias, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td>Meta Title:</td>
							<td><?php echo draw_input_field('cont_meta_title_'.$lid, $meta_title, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td><nobr>Meta Description:</nobr></td>
							<td><?php echo draw_input_field('cont_meta_description_'.$lid, $meta_desc, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td>Meta Keywords:</td>
							<td><?php echo draw_input_field('cont_meta_keywords_'.$lid, $meta_keyw, 'style="width:99%"'); ?></td>
						</tr>
						<tr>
							<td valign="top"><?php echo TEXT_CONTENT; ?></td>
							<td>
								<textarea name="cont_<?php echo $lid ?>" id="cont_<?php echo $lid ?>"><?php echo $text ?></textarea>
							</td>
						</tr>
					</table>
				</div>
				<?php } ?>
			</div>
		</div>
		<div id="misc">
			<table width="100%">
					<tr>
						<td width="50%" valign="top">
							<div id="content_manager_left">
								<h3><a href="#">Allgemein</a></h3>
								<div>
									<table width="100%">
										<?php
											$file_flag = $db->db_query("SELECT file_flag AS id, file_flag_name AS text FROM ".TABLE_CM_FILE_FLAGS);
											while(!$file_flag->EOF) {
												$file_flag_array[] = array('id' => $file_flag->fields['id'], 'text' => $file_flag->fields['text']);
												$file_flag->MoveNext();
											}
											$link_target[] = array('id' => '', 'text' => '');
											$link_target[] = array('id' => '_blank', 'text' => '_blank');
											$link_target[] = array('id' => '_self', 'text' => '_self');
											
											$link_type[] = array('id' => '', 'text' => '');
											$link_type[] = array('id' => 'nofollow', 'text' => 'nofollow');
											$link_type[] = array('id' => 'follow', 'text' => 'follow');
											?>
										<tr>
											<td class="main" align="right" width="50%" valign="top"><?php echo TEXT_CONTENT_GROUP; ?></td>
											<td class="main"><?php echo draw_input_field('content_group',$content_group,'size="5"'); ?></td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top"><?php echo TEXT_FILE_FLAG; ?></td>
											<td class="main"><?php echo draw_pull_down_menu('file_flag',$file_flag_array,$content->fields['file_flag']); ?></td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top"><?php echo TEXT_SORT_ORDER; ?></td>
											<td class="main"><?php echo draw_input_field('sort_order',$content->fields['sort_order'],'size="5"'); ?></td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top"><?php echo TEXT_STATUS; ?></td>
											<td class="main"><?php
												echo draw_checkbox_field('status', 'yes', ($content->fields['content_status']=='1' ? true : ($_GET['action']=='new' ? true : false))).' '.TEXT_STATUS_DESCRIPTION;
									
												?>
											</td>
										</tr>
										<?php
										if(GROUP_CHECK=='true') {
											$customers_statuses_array = get_customers_statuses();
											$customers_statuses_array = array_merge(array(array('id'=>'all','text'=>TXT_ALL)),$customers_statuses_array);
											?>
											<tr>
												<td class="main" style="border: 1px solid #b20000; border-width: 1px 0 1px 1px; background:#FFE9A6" valign="top">
													<?php echo ENTRY_CUSTOMERS_STATUS; ?>
												</td>
												<td class="main" style="border: 1px solid #b20000; border-width: 1px 1px 1px 0; background:#FFE9A6">
													<?php
													for($i=0;$n=sizeof($customers_statuses_array),$i<$n;$i++) {
														if(strstr($content->fields['group_ids'],'c_'.$customers_statuses_array[$i]['id'].'_group'))
															$checked='checked ';
														else
															$checked='';
									
														echo '<input type="checkbox" name="groups[]" value="'.$customers_statuses_array[$i]['id'].'"'.$checked.' /> '.$customers_statuses_array[$i]['text'].'<br />';
													}
													?>
												</td>
											</tr>
											<?php
										}
										?>
										<tr>
											<td class="main" align="right">Soll der Content einem anderen in der Box Darstellung unterordnet werden?</td>
											<td class="main" valign="top">
												<select name="parent">
													<?php echo contentTree(0, $content->fields['parent_id']); ?> 
												</select>
											</td>
										</tr>
										<tr>
											<td class="main" align="right">Link:</td>
											<td class="main"><?php echo draw_input_field('content_out_link',$content->fields['content_out_link'], 'style="width:99%"'); ?></td>
										</tr>
										<tr>
											<td class="main" align="right">Ziel:</td>
											<td class="main"><?php echo draw_pull_down_menu('content_link_target',$link_target,$content->fields['content_link_target']); ?></td>
										</tr>
										<tr>
											<td class="main" align="right">Type:</td>
											<td class="main"><?php echo draw_pull_down_menu('content_link_type',$link_type,$content->fields['content_link_type']); ?></td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top">
												<?php echo TEXT_UPLOAD_FILE; ?>
											</td>
											<td class="main" valign="top">
												<?php 
													echo TEXT_FILE_DESCRIPTION.'<br />'.
													draw_file_field('file_upload').'<br />
													'.TEXT_UPLOAD_FILE_LOCAL;
												?>
											</td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top"><?php echo TEXT_CHOOSE_FILE; ?></td>
											<td class="main">
												<?php
												if($dir= opendir(DIR_FS_CATALOG.'media/content/')){
													while  (($file = readdir($dir)) !==false) {
														if(is_file( DIR_FS_CATALOG.'media/content/'.$file) and ($file !="index.html"))
															$files[]=array('id' => $file, 'text' => $file);
													}
													closedir($dir);
												}
												if($content->fields['content_file']=='') {
													$default_array[]=array('id' => 'default','text' => TEXT_SELECT);
													$default_value='default';
													if(count($files) == 0)
														$files = $default_array;
													else
														$files=array_merge($default_array,$files);
												} else {
													$default_array[]=array('id' => 'default','text' => TEXT_NO_FILE);
													$default_value=$content->fields['content_file'];
													if(count($files) == 0)
														$files = $default_array;
													else
														$files=array_merge($default_array,$files);
												}
												echo TEXT_CHOOSE_FILE_SERVER.'<br /><br />';
												echo draw_pull_down_menu('select_file',$files,$default_value);
												if($content->fields['content_file']!='')
													echo '<br />'.TEXT_CURRENT_FILE.' <b>'.$content->fields['content_file'].'</b><br />';
												?>
											</td>
										</tr>
									</table>
								</div>
							</div>
						</td>
						<td valign="top" style="padding-left:10px">
							<div id="content_manager_right">
								<h3><a href="#">Darstellung</a></h3>
								<div>
									<table width="100%">
										<tr>
											<td class="main" align="right" width="50%" valign="top">
												Welche Spalten des Templates sollen dargestellt werden?
											</td>
											<td class="main">
												<table>
													<tr>
														<td width="1" align="left" valign="top">
															<?php echo image('images/template_prod.gif', 'Content Seite'); ?>
														</td>
														<td align="left">
															<?php
															if(isset($_GET['coID'])) {
																echo draw_selection_field('content_col_top', 'checkbox', '1', $content->fields['content_col_top']==1 ? true : false).' 1 oben<br />';
																echo draw_selection_field('content_col_left', 'checkbox', '1', $content->fields['content_col_left']==1 ? true : false).' 2 linke Spalte<br />';
																echo draw_selection_field('content_col_right', 'checkbox', '1', $content->fields['content_col_right']==1 ? true : false).' 3 rechte Spalte<br />';
																echo draw_selection_field('content_col_bottom', 'checkbox', '1', $content->fields['content_col_bottom']==1 ? true : false).' 4 unten<br />';
															} else {
																echo draw_selection_field('content_col_top', 'checkbox', '1', (GLOBAL_COLUMN_TOP == 1 ? true : false)).' 1 oben<br />';
																echo draw_selection_field('content_col_left', 'checkbox', '1', (GLOBAL_COLUMN_LEFT == 1 ? true : false)).' 2 linke Spalte<br />';
																echo draw_selection_field('content_col_right', 'checkbox', '1', (GLOBAL_COLUMN_RIGHT == 1 ? true : false)).' 3 rechte Spalte<br />';
																echo draw_selection_field('content_col_bottom', 'checkbox', '1', (GLOBAL_COLUMN_BOTTOM == 1 ? true : false)).' 4 unten<br />';
															}
															?>
														</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top">
												PDF Button anzeigen?
											</td>
											<td class="main">
												<?php echo draw_selection_field('content_show_pdf', 'checkbox', '1', (isset($_GET['coID']) ? $content->fields['content_show_pdf'] : GLOBAL_CONTENT_SHOW_PDF_BUTTON)==1 ? true : false); ?>
											</td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top">
												"Drucken" Button anzeigen?
											</td>
											<td class="main">
												<?php echo draw_selection_field('content_show_print', 'checkbox', '1', (isset($_GET['coID']) ? $content->fields['content_show_print'] : GLOBAL_CONTENT_SHOW_PRINT_BUTTON)==1 ? true : false); ?>
											</td>
										</tr>
										<tr>
											<td class="main" align="right" valign="top">
												"zurück" Button anzeigen?
											</td>
											<td class="main">
												<?php echo draw_selection_field('content_show_back', 'checkbox', '1', (isset($_GET['coID']) ? $content->fields['content_show_back'] : GLOBAL_CONTENT_SHOW_BACK_BUTTON)==1 ? true : false); ?>
											</td>
										</tr>
									</table>
								</div>
							</div>
						</td>
					</tr>
			</table>
		</div>
	</div>
	<input type="hidden" name="hidden_tab" id="hidden_tab" />
</form>
<script>
	$(function(){
		var opts_long = {lang:'<?php echo $_SESSION['language_code'] ?>',styleWithCSS:true,cssfiles:['includes/wysiwyg/css/textarea.css'],height:250,toolbar:'maxi',fmOpen:function(callback){$('<div id="myelfinder" />').elfinder({url:'includes/wysiwyg/connector.php',lang : '<?php echo $_SESSION['language_code'] ?>',dialog:{width:700,modal:true,title:'Dateimanager'},closeOnEditorCallback:true,editorCallback:callback});}
		}
		$('#content_manager').tabs({
			fx:{opacity:'toggle'},
			select: function(event, ui){
				var tabName = ui.panel.id;
				$('input#hidden_tab').val(tabName);
				window.location.hash = tabName;
				if(tabName == 'desc') {
					$('#tabs').tabs({fx:{opacity:'toggle'},
						show: function(event, ui){
							var lId = ui.panel.id.substring(9);
			        		setTimeout(function(){$('#cont_'+lId).elrte(opts_long);},500);
						},
						select: function(event, ui){
							var lId = ui.panel.id.substring(9);
							setTimeout(function(){$('#cont_'+lId).elrte(opts_long);},500);
						}
					});
	    		}else if(tabName == 'misc'){
		    		var accordionLeft=$("#content_manager_left");var indexLeft=$.cookie("content_accordion_left");var activeLeft;if(indexLeft!==null){activeLeft=accordionLeft.find("h3:eq("+indexLeft+")");}else{activeLeft = 0;}accordionLeft.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeLeft,change:function(event, ui){var indexLeft = $(this).find("h3").index(ui.newHeader[0]);$.cookie("content_accordion_left",indexLeft,{path:"/"});}});var accordionRight=$("#content_manager_right");var indexRight = $.cookie("content_accordion_right");var activeRight;if(indexRight!==null){activeRight=accordionRight.find("h3:eq("+indexRight+")");}else{activeRight = 0;}accordionRight.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeRight,change:function(event,ui){var indexRight=$(this).find("h3").index(ui.newHeader[0]);$.cookie("content_accordion_right",indexRight,{path:"/"});}});
	    		}
	    	},
	    	show: function(event, ui){
				var tabName = ui.panel.id;
				$('input#hidden_tab').val(tabName);
				window.location.hash = tabName;
				if(tabName == 'desc') {
					$('#tabs').tabs({fx:{opacity:'toggle'},
						show: function(event, ui){
							var lId = ui.panel.id.substring(9);
							setTimeout(function(){$('#cont_'+lId).elrte(opts_long);},500);
						},
						select: function(event, ui){
							var lId = ui.panel.id.substring(9);
							setTimeout(function(){$('#cont_'+lId).elrte(opts_long);},500);
						}
					});
	    		}else if(tabName == 'misc'){
		    		var accordionLeft=$("#content_manager_left");var indexLeft=$.cookie("content_accordion_left");var activeLeft;if(indexLeft!==null){activeLeft=accordionLeft.find("h3:eq("+indexLeft+")");}else{activeLeft = 0;}accordionLeft.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeLeft,change:function(event, ui){var indexLeft = $(this).find("h3").index(ui.newHeader[0]);$.cookie("content_accordion_left",indexLeft,{path:"/"});}});var accordionRight=$("#content_manager_right");var indexRight = $.cookie("content_accordion_right");var activeRight;if(indexRight!==null){activeRight=accordionRight.find("h3:eq("+indexRight+")");}else{activeRight = 0;}accordionRight.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeRight,change:function(event,ui){var indexRight=$(this).find("h3").index(ui.newHeader[0]);$.cookie("content_accordion_right",indexRight,{path:"/"});}});
	    		}
	    	}
		});
	});
</script>